﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.IO;
using System.Text;

using Jungle.Users;
using Jungle.Code.Core;
using Jungle.Code.Utils;
using Jungle.Users.WebControls;


namespace Jungle.Admin
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected override void OnInit(EventArgs e)
        {
            SessionKeeper sk = new SessionKeeper();
            sk.SessionId = Session.SessionID.ToString();
            sk.GetData();
            if (new Jungle.Users.UserManager(sk.UserId).RoleId > 2) Response.Redirect(UrlHelper.GetAdminUrl());

            UserManager um = new UserManager();
            um.UserId = sk.UserId;
            um.GetById();

            if (um.RoleId > 2)
            {
                UserTree1.Visible = false;
                hp_AddU.Visible = false;
            }

            if (Request["code"] != null) Register1.Visible = true;
            if(Request["cmd"] != null)
            switch (Request["cmd"])
            {
                case "add": Register1.Visible = true; break;
                case "edit": UserInfo1.Visible = true; break;
                case "show": ShowUser(); break;
            }

            base.OnInit(e);
        }
        // -----------------------------------------------------------------
        protected void ShowUser()
        {
            if (Request["id"] != null)
            {
                UserManager um = new UserManager();
                um.UserId = Convert.ToInt32(Request["id"]);
                um.GetById();

                lb_UserInfo.Text = "<b>Информация о пользователе:</b><br/><br/>";
                lb_UserInfo.Text += "<b>Имя:</b> " + um.Name + " " + um.Fname + "<br/>";
                lb_UserInfo.Text += "<b>Email:</b> " + um.Email + "<br/>";
                lb_UserInfo.Text += "<b>Должность:</b> " + UserManager.GetUserRole(um.RoleId) + "<br/>";
                
            }
        }
    }
}
